//
//  CNDiscountCouponCell.m
//  BeeQuick_19
//
//  Created by clinging on 16/9/26.
//  Copyright © 2016年 CN Team. All rights reserved.
//

#import "CNDiscountCouponCell.h"
#import "Masonry.h"

@implementation CNDiscountCouponCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    // 优惠券背景图片
    UIImageView *backGroundImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"v2_coupon_yellow"]];
    //    backGroundImg.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:backGroundImg];
    
    [backGroundImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(5);
        make.left.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.right.equalTo(self.contentView).offset(-10);
    }];
    _backgroundImg = backGroundImg;
    
    UIImageView *roundView = [[UIImageView alloc]init];
    [backGroundImg addSubview:roundView];
    //    roundView.backgroundColor = [UIColor colorWithRed:255/255.0 green:216/255.0 blue:0 alpha:1];
    roundView.image = [UIImage imageNamed:@"v2_coupon_verify_selected"];
    [roundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backGroundImg);
        make.left.equalTo(backGroundImg).offset(20);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    _roundImg = roundView;
    roundView.layer.cornerRadius = 30;
    roundView.clipsToBounds = YES;
    
    UILabel *priceLB = [[UILabel alloc]init];
    [roundView addSubview:priceLB];
    priceLB.text = @"$5";
    priceLB.font = [UIFont systemFontOfSize:12];
    priceLB.textColor = [UIColor whiteColor];
    [priceLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(roundView).offset(10);
        make.left.equalTo(roundView).offset(17);
        make.right.equalTo(roundView).offset(-10);
        make.height.equalTo(@20);
    }];
    _valueLB = priceLB;
    
    UIImageView *usedImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"v2_coupon_used"]];
    [roundView addSubview:usedImg];
    usedImg.transform = CGAffineTransformMakeRotation(-M_PI_4/90*23);
    [usedImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(priceLB);
        make.left.equalTo(roundView).offset(13);
        make.top.equalTo(priceLB.mas_bottom);
        make.bottom.equalTo(roundView).offset(-10);
    }];
    _usedImg = usedImg;
    
    
    UILabel *wordLB = [[UILabel alloc]init];
    wordLB.text = @"xxoo";
    wordLB.textColor = [UIColor colorWithRed:174/255.0 green:128/255.0 blue:95/255.0 alpha:1];
    [backGroundImg addSubview:wordLB];
    wordLB.font = [UIFont systemFontOfSize:12];
    [wordLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(backGroundImg).offset(50);
        make.top.equalTo(backGroundImg).offset(10);
    }];
    _wordLB = wordLB;
    
    UIView *leftLine = [[UIView alloc]init];
    leftLine.backgroundColor = [UIColor lightGrayColor];
    [backGroundImg addSubview:leftLine];
    [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(wordLB.mas_centerY);
        make.left.equalTo(roundView.mas_right).offset(25);
        make.right.equalTo(wordLB.mas_left).offset(-5);
        make.height.equalTo(@1);
    }];
    
    UIView *rightLIne = [[UIView alloc]init];
    rightLIne.backgroundColor = [UIColor lightGrayColor];
    [backGroundImg addSubview:rightLIne];
    [rightLIne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(wordLB.mas_right).offset(5);
        make.right.equalTo(backGroundImg).offset(-5);
        make.centerY.equalTo(wordLB);
        make.height.equalTo(@1);
    }];
    
    //有效期一系列label
    UILabel *dataFromLB = [[UILabel alloc]init];
    dataFromLB.text = @"有效期自:";
    dataFromLB.textColor = [UIColor colorWithRed:174/255.0 green:128/255.0 blue:95/255.0 alpha:1];
    dataFromLB.font = [UIFont systemFontOfSize:10];
    [backGroundImg addSubview:dataFromLB];
    [dataFromLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftLine).offset(20);
        make.top.equalTo(wordLB.mas_bottom).offset(5);
        //        make.right.equalTo(wordLB.mas_left).offset(-25);
    }];
    
    UILabel *startTimeLB = [[UILabel alloc]init];
    [backGroundImg addSubview:startTimeLB];
    startTimeLB.text = @"2015-4-28";
    startTimeLB.font = [UIFont systemFontOfSize:10];
    startTimeLB.textColor = [UIColor colorWithRed:174/255.0 green:128/255.0 blue:95/255.0 alpha:1];
    [startTimeLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dataFromLB.mas_right);
        make.top.equalTo(dataFromLB);
    }];
    _start_timeLB = startTimeLB;
    
    UILabel *datatoLB = [[UILabel alloc]init];
    datatoLB.text = @"至:";
    datatoLB.font = [UIFont systemFontOfSize:10];
    datatoLB.textColor = [UIColor colorWithRed:174/255.0 green:128/255.0 blue:95/255.0 alpha:1];
    [backGroundImg addSubview:datatoLB];
    [datatoLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(startTimeLB.mas_right).offset(5);
        make.top.equalTo(startTimeLB);
    }];
    
    UILabel *endtimeLB = [[UILabel alloc]init];
    endtimeLB.text  = @"2018-4-28";
    endtimeLB.font = [UIFont systemFontOfSize:10];
    endtimeLB.textColor = [UIColor colorWithRed:174/255.0 green:128/255.0 blue:95/255.0 alpha:1];
    [backGroundImg addSubview:endtimeLB];
    [endtimeLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(datatoLB.mas_right);
        make.top.equalTo(datatoLB);
    }];
    _end_timeLB = endtimeLB;
    
    UIView *middleLine = [[UIView alloc]init];
    middleLine.backgroundColor = [UIColor lightGrayColor];
    [backGroundImg addSubview:middleLine];
    [middleLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dataFromLB);
        make.right.equalTo(endtimeLB);
        make.top.equalTo(endtimeLB.mas_bottom).offset(5);
        make.height.equalTo(@1);
    }];
    
    UILabel *descriptionLB = [[UILabel alloc]init];
    descriptionLB.text = @"ksdsdklsdnsdknsdnfsddngkldgnskklsdngkldsngklsnsdnklsndlsn";
    descriptionLB.textColor = [UIColor colorWithRed:174/255.0 green:128/255.0 blue:95/255.0 alpha:1];
    descriptionLB.numberOfLines = 0;
    descriptionLB.font = [UIFont systemFontOfSize:8];
    [backGroundImg addSubview:descriptionLB];
    [descriptionLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(middleLine.mas_bottom).offset(5);
        make.left.equalTo(leftLine);
        make.right.equalTo(rightLIne);
        make.bottom.equalTo(backGroundImg).offset(-10);
    }];
    _descLB = descriptionLB;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}

@end
